home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / T / TileCDEF.cpt / TileTest.pas < prev    next >
Pascal/Delphi Source File  |  1989-02-07  |  5KB  |  209 lines

  1. Program TileTest;
  2.  
  3. {$U-}
  4. {$R TileTest.rsrc}
  5.  
  6. Uses
  7.   MemTypes,QuickDraw,OSIntf,ToolIntf,Sound;
  8.   
  9. Const
  10.   AppleMenu     = 128;
  11.   FileMenu      = 129;
  12.   EditMenu      = 130;
  13.   
  14. Var
  15.   myMenus       : array [AppleMenu..EditMenu] of MenuHandle;
  16.   GrowArea      : Rect;
  17.   theWindow     : WindowPtr;
  18.   theControl    : ControlHandle;
  19.   RabbitControl : ControlHandle;
  20.   PigControl    : ControlHandle;
  21.  
  22. Procedure ProcessMenu(codeWord : Longint);
  23. Var
  24.   menuNum       : Integer;
  25.   itemNum       : Integer;
  26.   NameHolder    : Str255;
  27.   dummy         : Integer;
  28. Begin
  29.   if codeWord = 0 then Exit;
  30.   menuNum:= HiWord(codeWord);
  31.   itemNum:= LoWord(codeWord);
  32.   case menuNum of
  33.     AppleMenu :
  34.       begin
  35.         GetItem(myMenus[AppleMenu],itemNum,NameHolder);
  36.         dummy := OpenDeskAcc(NameHolder);
  37.       end;
  38.     FileMenu : ExitToShell;
  39.     EditMenu : if NOT SystemEdit(itemNum - 1) then ;
  40.   end;
  41.   HiliteMenu(0);
  42. End;
  43.  
  44. Procedure DealWithMouseDowns(theEvent: EventRecord);
  45. Var
  46.   whichWindow   : WindowPtr;
  47.   mouseLoc      : Point;
  48.   windowLoc     : Integer;
  49.   position      : LongInt;
  50.   whichControl  : ControlHandle;
  51.   resHdl        : Handle;
  52.   errCode       : OSErr;
  53. Begin
  54.   mouseLoc:= theEvent.where;
  55.   windowLoc:= FindWindow(mouseLoc,whichWindow);
  56.   case windowLoc of
  57.     inMenuBar   : ProcessMenu(MenuSelect(mouseLoc));
  58.     inSysWindow : SystemClick(theEvent,whichWindow);
  59.     inDrag      : DragWindow(whichWindow,mouseLoc,screenBits.bounds);
  60.     inZoomIn,inZoomOut :
  61.       begin
  62.         if TrackBox(whichWindow,mouseLoc,windowLoc) then begin
  63.           SetPort(whichWindow);
  64.           ClipRect(whichWindow^.portRect);
  65.           EraseRect(whichWindow^.portRect);
  66.           ZoomWindow(whichWindow,windowLoc,true);
  67.           InvalRect(whichWindow^.portRect);
  68.         end;
  69.       end;
  70.     inGrow :
  71.       begin
  72.         position:= GrowWindow(whichWindow,mouseLoc,GrowArea);
  73.         if position <> 0 then begin
  74.           SizeWindow(whichWindow,loword(position),hiword(position),false);
  75.           SetPort(whichWindow);
  76.           InvalRect(whichWindow^.portRect);
  77.         end;
  78.       end;
  79.     inGoAway :
  80.       begin
  81.         if TrackGoAway(whichWindow,mouseLoc) then ExitToShell;
  82.       end;
  83.     inContent :
  84.       begin
  85.         if whichWindow <> FrontWindow then
  86.           SelectWindow(whichWindow)
  87.         else begin
  88.           SetPort(whichWindow);
  89.           GlobalToLocal(mouseLoc);
  90.           if FindControl(mouseLoc,whichWindow,whichControl) = 0 then Exit;
  91.           if TrackControl(whichControl,mouseLoc,nil) = 0 then Exit;
  92.           if whichControl = RabbitControl then begin
  93.             resHdl:= GetResource('snd ',128);
  94.             errCode:= SndPlay(nil,resHdl,true);
  95.             ReleaseResource(resHdl);
  96.           end;
  97.        end;
  98.      end;
  99.   end;
  100. End;
  101.  
  102. Procedure DealWithKeyDowns(theEvent: EventRecord);
  103. Var
  104.   CharCode  : char;
  105. Begin
  106.   CharCode:= CHR(BitAnd(theEvent.message,charCodeMask));
  107.   if BitAnd(theEvent.modifiers,CmdKey) = CmdKey
  108.     then ProcessMenu(MenuKey(CharCode));
  109. End;
  110.  
  111. Procedure DealWithActivates(theEvent: EventRecord);
  112. Var
  113.   TargetWindow    : WindowPtr;
  114. Begin
  115.   TargetWindow := WindowPtr(theEvent.message);
  116.   if Odd(theEvent.modifiers)
  117.     then SetPort(TargetWindow);
  118. End;
  119.  
  120. Procedure DealWithUpdates(theEvent: EventRecord);
  121. Var
  122.   UpDateWindow  : WindowPtr;
  123.   tempPort      : WindowPtr;
  124. Begin
  125.   UpDateWindow := WindowPtr(theEvent.message);
  126.   GetPort(tempPort);
  127.   SetPort(UpDateWindow); 
  128.   BeginUpDate(UpDateWindow);
  129.     EraseRect(UpDateWindow^.portRect);
  130.     DrawControls(UpDateWindow);
  131.   EndUpDate(UpDateWindow);
  132.   SetPort(tempPort);
  133. End;
  134.  
  135. Procedure MainEventLoop;
  136. Var
  137.   Event        : EventRecord;
  138. Begin
  139.   repeat
  140.     SystemTask;
  141.     if GetNextEvent(everyEvent, Event) then
  142.       case Event.what of
  143.         mouseDown   : DealWithMouseDowns(Event);
  144.         AutoKey     : DealWithKeyDowns(Event);
  145.         KeyDown     : DealWithKeyDowns(Event);
  146.         ActivateEvt : DealWithActivates(Event);
  147.         UpdateEvt   : DealWithUpdates(Event);
  148.       end; {case}
  149.   until FALSE;
  150. End;
  151.  
  152. Procedure SetupMacintosh;
  153. Begin
  154.   MaxApplZone;
  155.   MoreMasters;
  156.   MoreMasters;
  157.   MoreMasters;
  158.  
  159.   FlushEvents(everyEvent,0);
  160.  
  161.   InitGraf(@thePort);
  162.   InitFonts;
  163.   InitWindows;
  164.   InitMenus;
  165.   TEInit;
  166.   InitDialogs(nil);
  167. End;
  168.  
  169. Procedure SetupMenus;
  170. Var
  171.   index    : Integer;
  172. Begin
  173.   for index:= AppleMenu to EditMenu do begin
  174.     myMenus[index] := GetMenu(index);
  175.     InsertMenu(myMenus[index],0);
  176.   end;
  177.   AddResMenu(myMenus[AppleMenu],'DRVR');
  178.   DrawMenuBar;
  179. End;
  180.  
  181. Procedure SetupStuff;
  182. Var
  183.   tempRect  : Rect;
  184. Begin
  185.   with screenBits.bounds do
  186.     SetRect(GrowArea,100,100,right,bottom);
  187.     
  188.   SetRect(tempRect,50,50,400,300);
  189.   theWindow:= NewWindow(nil,tempRect,'hello',true,8,pointer(-1),true,0);
  190.   
  191.   RabbitControl:= GetNewControl(128,theWindow);
  192.   PigControl:= GetNewControl(129,theWindow);
  193.   
  194.   SetRect(tempRect,100,100,164,164);
  195.   theControl:= NewControl(theWindow,tempRect,'',true,129,0,0,160,0);
  196.   
  197.   HiliteControl(theControl,255);
  198. End;
  199.  
  200. Begin
  201.   SetupMacintosh;
  202.  
  203.   SetupMenus;
  204.   SetupStuff;
  205.   InitCursor;
  206.   
  207.   MainEventLoop;
  208. End.
  209.